package com.example.mr5.mygame.gameCatchCat;

import android.app.Activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.mr5.mygame.R;
import com.example.mr5.mygame.game2048.AnimLayer;
import com.example.mr5.mygame.utils.AdID;
import com.example.mr5.mygame.utils.SharePreferenceUtil;

import cn.waps.AppConnect;
import cn.waps.AppListener;

/**
 * Created by Mr.5
 * Date：2016/5/8.
 * Time：14:18
 */
public class CatchCatActivity extends Activity implements View.OnClickListener {
    private ImageView barBack;
    private TextView barTitle;
    SharePreferenceUtil util;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

        setContentView(new GameView(this));
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.bar);
        AppConnect.getInstance("95cec2974bd7db4551fc275772d992a9", AdID.ID, this);
        util = new SharePreferenceUtil(this);

        AppConnect.getInstance(this);
        initView();
        AppConnect.getInstance(this).initPopAd(this);
        AppConnect.getInstance(this).setPopAdNoDataListener(new AppListener() {

            @Override
            public void onPopNoData() {
                Log.i("debug", "插屏广告暂无可用数据");
            }

        });
        // 显示插屏广告
        if(util.getShowAd().equals("yes")){
            AppConnect.getInstance(this).showPopAd(this);
        }

    }
    private void initView(){
        barBack = (ImageView) findViewById(R.id.header_left_btn);
        barBack.setOnClickListener(this);
        barTitle = (TextView) findViewById(R.id.header_text);
        barTitle.setText(getTitle());
    }
    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.header_left_btn){
            showDialog();
        }
    }
    @Override
    public void onBackPressed() {
        showDialog();
    }

    private void showDialog() {
        new AlertDialog.Builder(CatchCatActivity.this).setTitle("你好")
                .setMessage("是否退出游戏？")
                .setPositiveButton("是", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton("否", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        }).show();
    }
}
